﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WebShop.DataService;
using WebShop.Classes.Messaging;

namespace WebShop.Classes
{
    /// <summary>
    /// Static storage for session data
    /// </summary>
    public static class ConfigStorage
    {
        /// <summary>
        /// User language
        /// </summary>
        public static string Language { get; set; }

        /// <summary>
        /// Authed user data
        /// </summary>
        public static User User { get; set; }

        /// <summary>
        /// Cart
        /// </summary>
        public static OrderFull Order
        { 
            get {
                return HttpContext.Current.Session["cart"] as OrderFull;
            } 
            set{
                HttpContext.Current.Session["cart"] = value;
            } 
        }

        /// <summary>
        /// Messages list
        /// </summary>
        public static List<Message> Messages { get; set; }

        static ConfigStorage()
        {
            if (Order == null)
            {
                ClearOrder();
            }
        }

        /// <summary>
        /// Clear cart
        /// </summary>
        public static void ClearOrder()
        {
            HttpContext.Current.Session["cart"] = new OrderFull();
            Order.Composition = new List<OrderPosition>();
            Messages = new List<Message>();
        }

        /// <summary>
        /// Clear message list
        /// </summary>
        public static void ClearMessages()
        {
            Messages.Clear();
        }
    }
}